package it.abc.sicsic.view.backing.template;

import it.abc.sicsic.view.backing.Costants;
import it.abc.sicsic.view.backing.NavigationItem;

import it.abc.sicsic.view.backing.tree.TreeCore;

import it.abc.sicsic.view.backing.tree.TreeItem;
import it.abc.sicsic.view.backing.tree.TreeNode;

import java.util.ArrayList;

import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

import javax.faces.context.FacesContext;

import oracle.adf.view.rich.component.rich.data.RichTree;

import org.apache.myfaces.trinidad.model.ChildPropertyTreeModel;
import org.apache.myfaces.trinidad.model.TreeModel;
@ManagedBean(name = "backing_nauticaTemplateTree")
@SessionScoped

public class NuticaTemplateTree {
    private Object instance = null;
    private transient TreeModel model = null;
    private ArrayList<TreeCore> root;
    private RichTree tree;

    public NuticaTemplateTree() {
        super();
        root = new ArrayList<TreeCore>();
        TreeNode clientiNode = new TreeNode("Clienti");
        clientiNode.addChildren(new TreeItem("Gestione","GestisciCliente",Costants.Icon.MANAGEMENT))
                   .addChildren(new TreeItem("Inserimento","InserisciCliente",Costants.Icon.INSERT));
        TreeNode barcheNode = new TreeNode("Barche");
        barcheNode.addChildren(new TreeItem("Gestione","GestisciBarca",Costants.Icon.MANAGEMENT))
                  .addChildren(new TreeItem("Inserimento","InserisciBarca",Costants.Icon.INSERT));
        TreeNode skipperNode = new TreeNode("Skipper");
        skipperNode.addChildren(new TreeItem("Gestione","GestisciSkipper",Costants.Icon.MANAGEMENT))
                  .addChildren(new TreeItem("Inserimento","InserisciSkipper",Costants.Icon.INSERT));
        TreeNode nauticaNode = new TreeNode("Nautica");        
        TreeNode speseNode = new TreeNode("Spese");
        speseNode.addChildren(new TreeItem("Gestione","GestisciSpese",Costants.Icon.MANAGEMENT))
                 .addChildren(new TreeItem("Inserimento","InserisciSpese",Costants.Icon.INSERT));
        root.add(clientiNode);
        root.add(barcheNode);
        root.add(skipperNode);
        root.add(nauticaNode);
        root.add(speseNode);
        
        setListInstance(root);
        if (tree==null) tree=new RichTree();
        tree.saveState(FacesContext.getCurrentInstance());
                
    }
    
    public TreeModel getModel() {
        if (model == null)
            model = new ChildPropertyTreeModel(instance, "children");
        return model;
    }

    public void setListInstance(List instance) {
        this.instance = instance;
        model = null;
    }

    public void setTree(RichTree tree) {
        this.tree = tree;
    }

    public RichTree getTree() {
        return tree;
    }
}
